<?php 
/*
 * @分销商城
 * @功能说明：支付统一入口
 * @更新说明：暂无更新
 * @文件名 Ping.class.php
 * @编码 UTF-8
 * @创建时间 2016-1-22 下午6:13:52
 * @创建人 XING
 */
namespace service\ping;
require SCRIPT_ROOT.'/../../library/ping/init.php';
class Ping {
	const appkey = 'sk_live_eHeHuLTOWX1GeLSSe9mP0eH4';
	const appid = 'app_fHqffHPyHqfTH4u1';
	
	/*
	 * 支付入口
	 * @date: 2015-6-22 下午2:17:48
	 * @editor: XING
	 */
	public function payinit($order,$amount,$payChannel,$openId,$sub='商城支付订单',$body='订单付款支付'){
		\Pingpp\Pingpp::setApiKey(self::appkey);
		$data = \Pingpp\Charge::create(array(
				'order_no'  => $order,
				'amount'    => $amount*100,
				'app'       => array('id'=>self::appid),
				'channel'   => $payChannel,
				'currency'  => 'cny',
				'client_ip' => $_SERVER['SERVER_ADDR'],
				'subject'   => $sub,
				'body'      => $body,
				'extra' => array('open_id'=>$openId),
				'metadata' => array('order_id'=>$order)
		));
		return $data;
	}
	
    /*
	 * 分销商城_售后退款入口
	 * @date: 2016-3-31 下午2:05:54
	 * @editor: XING
	 */
	public function payRefund($cid,$order_id,$mon){
		\Pingpp\Pingpp::setApiKey(self::appkey);
		$ch = \Pingpp\Charge::retrieve($cid);
		$reback = $ch->refunds->create(
				array(
						'amount' => $mon*100,
						'description' => $order_id
				)
		);
	
		return $reback;
	}

}

?>